package org.hzz.snake;

import java.awt.EventQueue;

import javax.swing.JFrame;

public class SnakeMVC {
    private SnakeView snakeView;
    private SnakeModel snakeModel;
    private SnakeController snakeController;

    private String title;

    public SnakeMVC(String title) {
        snakeView = new SnakeView();
        snakeModel = new SnakeModel();
        snakeController = new SnakeController(snakeModel, snakeView);
        this.title = title;
        
    }

    // 启动
    public void start(){
         // 使用 EventQueue.invokeLater() ETD线程来专门处理GUI程序
        EventQueue.invokeLater(() -> {
            initFrame(title);
            snakeController.startGame();
        });
    }

    private void initFrame(String title) {
        JFrame frame = new JFrame(title);
        // 窗口Frame添加面板Panel
        frame.add(this.snakeView);
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // frame.setSize(400, 400);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
